package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.MaintenanceForm;
import com.amsp.oa.oademo.service.MaintenanceFormService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "工务维修申请单管理")
@RestController
@RequestMapping("/api/maintenance")
public class MaintenanceFormController {

    @Autowired
    private MaintenanceFormService maintenanceFormService;

    @ApiOperation("分页查询工务维修申请单")
    @GetMapping("/page")
    public IPage<MaintenanceForm> getPage(
            @ApiParam(value = "当前页码", required = true) @RequestParam Integer current,
            @ApiParam(value = "每页记录数", required = true) @RequestParam Integer size,
            @ApiParam(value = "申请部门") @RequestParam(required = false) String applyDepartment,
            @ApiParam(value = "申请人") @RequestParam(required = false) String applicant) {
        return maintenanceFormService.getPage(current, size, applyDepartment, applicant);
    }

    @ApiOperation("保存工务维修申请单")
    @PostMapping("/save")
    public boolean save(@RequestBody MaintenanceForm maintenanceForm) {
        return maintenanceFormService.saveOrUpdate(maintenanceForm);
    }

    @ApiOperation("根据ID获取工务维修申请单")
    @GetMapping("/{id}")
    public MaintenanceForm getById(@PathVariable Long id) {
        return maintenanceFormService.getById(id);
    }

    @ApiOperation("删除工务维修申请单")
    @DeleteMapping("/{id}")
    public boolean removeById(@PathVariable Long id) {
        return maintenanceFormService.removeById(id);
    }
}